package com.gomore.opple.widgets.dialog;


import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.gomore.opple.R;

public class LoadingDialog extends ReDialog {
    private boolean mIsMonitorBackKey = true;

    public LoadingDialog(Context paramContext, int progressbarlayout, String paramString2, View DialogView, boolean isBackKey) {
        super(paramContext, progressbarlayout, null, DialogView, DialogButtonsStyle.LOADING);
        if (!TextUtils.isEmpty(paramString2))
            setMessage(".".equals(paramString2) ? "" : paramString2);

    }

    TextView messageTextView;
    ProgressBar mProgressBar;

    @Override
    protected int getDialogId() {
        return 0;
    }

    @Override
    protected void closeDialog() {
        if (getOwnerActivity() != null) {
            super.onBackPressed();
        } else {
            dismiss();
        }
    }

    // 关闭
    public void onClose() {
        mProgressBar.setVisibility(View.GONE);
        closeDialog();
    }

    public String getMessage() {
        return this.messageTextView.getText().toString();
    }

    /**
     * 隐藏文本内容
     */
    public void setHideMessage() {
        this.messageTextView.setVisibility(View.GONE);
    }

    /**
     * 设置内容
     *
     * @param paramString 内容数据
     */
    public void setMessage(String paramString) {
        if ((paramString == null) || ("".equals(paramString))) {
            this.messageTextView.setText("");
            this.messageTextView.setVisibility(View.GONE);
        } else {
            this.messageTextView.setText(paramString);
            this.messageTextView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void show() {
        try {
            mProgressBar.setVisibility(View.VISIBLE);
            super.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void init(DialogButtonsStyle paramDialogButtonsStyle) {
        super.init(paramDialogButtonsStyle);
        getWindow().setGravity(Gravity.CENTER);
        this.messageTextView = (TextView) this.mDialogView.findViewById(R.id.about_text);
        this.messageTextView.setVisibility(View.VISIBLE);
        this.mProgressBar = (ProgressBar) this.mDialogView.findViewById(R.id.init_spinny);
    }

    @Override
    public void onBackPressed() {
        if (mIsMonitorBackKey) {
            dismiss();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }

}
